package com.shitu.base.net.service;

import com.alibaba.fastjson.JSON;
import com.shitu.base.net.API;
import com.shitu.base.net.request.RequestHelper;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;

public class CommonService {


//    @POST("common/uploadImg")
//    Call<BaseResponse> uploadImg(@Body RequestBody body, @Query("token") String token);


    /**
     * http://52.83.146.189:88/slm/common/getAllCategorys
     *
     * @return
     */
    public static Request getAllCategorys() {
        String url = API.BASE_URL + "common/getAllCategorys";
        Map body = RequestHelper.getBase();
        body.put("params", new HashMap<>());

        String bodyStr = JSON.toJSONString(body);
        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), bodyStr);
        Request request = new Request.Builder().post(requestBody).url(url).build();
        return request;
    }

    public static Request updateImg(String file, String token) {
        String url = API.BASE_URL + "common/uploadImg?token=" + token;
        File f = new File(file);
        RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), f);
        RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).
                addFormDataPart("file", "image.jpg", fileBody).build();
        Request request = new Request.Builder().post(requestBody).url(url).build();
        return request;
    }

}
